package com.honeywen.mymvc.leetcode;


import java.util.ArrayList;
import java.util.List;

/**
 * 14. 最长公共前缀
 * 编写一个函数来查找字符串数组中的最长公共前缀。
 *
 * @author weiw@opera.com
 * @date 2018/7/30 下午8:11
 */
public class LongestCommonPrefix {

    public static String l3(String[] strs) {
        if (strs.length == 0) {
            return "";
        }
        if (strs.length == 1) {
            return strs[0];
        }

        int point = -1;

        loop:
        for (int i = 0; i < strs[0].length(); i++) {
            boolean flag = true;
            for (int j = 0; j < strs.length; j++) {

                if (point + 1 > strs[j].length() - 1) {
                    break loop;
                }

                char c = strs[0].charAt(point + 1);

                flag = c == strs[j].charAt(point + 1);
                if (!flag) {
                    break loop;
                }
            }
            point++;
        }


        return strs[0].substring(0, point + 1);

    }



    public static void main(String[] args) {


        System.out.println(l3(new String[]{"cc", "dc", "c"}));


    }
}
